﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using System.Configuration;

namespace MovieApp
{
    public class SettingsHandler : ApplicationSettingsBase
    {
        public SettingsHandler()
        {

        }

        [UserScopedSetting()]
        [DefaultSettingValue(@"E:\seriale")]
        public String MoviePath
        {
            get { return (String)this["MoviePath"]; }
            set { this["MoviePath"] = value; }
        }

        [UserScopedSetting()]
        [DefaultSettingValue("true")]
        public bool SaveOnExit
        {
            get { return (bool)this["SaveOnExit"]; }
            set { this["SaveOnExit"] = value; }
        }

        [UserScopedSetting()]
        [DefaultSettingValue("true")]
        public bool AutoSave
        {
            get { return (bool)this["AutoSave"]; }
            set { this["AutoSave"] = value; }
        }

        [UserScopedSetting()]
        [DefaultSettingValue("05:00")]
        public string AutoSaveInterval
        {
            get { return (string)this["AutoSaveInterval"]; }
            set { this["AutoSaveInterval"] = value; }
        }

        public uint AutoSaveIntervalMs
        {
            get
            {
                string[] vals = ((String)this["AutoSaveInterval"]).Split(':');
                uint ret = 0;
                uint min = 0;
                uint sec = 0;
                if (vals.Length >= 2)
                {
                    min = Convert.ToUInt32(vals[0]);
                    sec = Convert.ToUInt32(vals[1]);
                }
                ret = (min * 60 + sec) * 1000;
                return ret;
            }
        }

        public int AutoSaveMinutes
        {
            get
            {
                string[] vals = ((String)this["AutoSaveInterval"]).Split(':');
                if (vals.Length < 2)
                    return 0;
                return Convert.ToInt32(vals[0]);
            }
        }

        public int AutoSaveSeconds
        {
            get
            {
                string[] vals = ((String)this["AutoSaveInterval"]).Split(':');
                if (vals.Length < 2)
                    return 0;
                return Convert.ToInt32(vals[1]);
            }
        }
    }
}
